#!/bin/sh

#
# Copyright xgliu515@gmail.com
#

if [ $UID -eq 0 ]; then
	SUDO=
else
	SUDO=sudo
fi


KERNEL="-kernel $NK_KERNEL/arch/x86_64/boot/bzImage"
#INITRD="-initrd $NK_KERNEL/..."
INITRD=""


# CONSOLE="-nographic"
CONSOLE=""


QEMU=`which qemu-kvm 2>/dev/null`
if [ -n "$QEMU" ]; then
	QEMU="qemu-kvm"
else
	QEMU="qemu-system-x86_64"
fi


M=0
if [ -n "$1" ]; then
	M="$1"
fi

I=0
INFNUM=4
MODEL=e1000
while [ $I -lt $INFNUM ]; do
	NET="$NET -net nic,macaddr=52:54:00:00:$M:$I,vlan=$I,model=$MODEL -net tap,vlan=$I,ifname=tap-$M-$I,script=$NK_TOOLS/qemu-ifup,downscript=$NK_TOOLS/qemu-ifdown"
	I=`expr $I + 1`
done

DISK=$NK_TOOLS/netkindle.img
SIZE=1G
if [ ! -e $DISK ]; then
	echo "create disk"
	qemu-img create $DISK $SIZE
fi

HARDDISK="-hda $DISK"
MEMORY="-m 512"

$SUDO $QEMU \
	$CONSOLE \
	$HARDDISK \
	$MEMORY \
	$KERNEL \
	$INITRD \
	$NET \
	&

